<?php
/**
 * 百度地图类库封装
 * Created by Sublime Text 3.
 * @authors Rejeo (rejeo@qq.com)
 * @date    2018-04-22 00:11:57
 * @version $Id$
 */

class Baidumap
{
    /**
     * 获取地址获取经纬度信息
     * @param  string $address 地址信息
     * @return array
     */
    public static function getLngLat($address)
    {
        if (empty($address)) {
            return '';
        }
        $data = [
            'address' => $address,
            'ak' => config('baidumap.ak'),
            'output' => 'json'
        ];
        $url = config('baidumap.url').config('baidumap.geocoder').http_build_query($data);
        $res = doCurl($url);
        // dump($res);exit; // 接口调试
        if ($res) {
            return json_decode($res,true);
        }
        return [];
    }

    // https://api.map.baidu.com/staticimage/v2
    /**
     * 根据经纬度或者地址来获取百度地图
     * @param [type] $center [description]
     */
    public static function staticimage($center)
    {
        if (empty($staticimage)) {
            return '';
        }
        $data = [
            'ak' => config('baidumap.ak'),
            'width' => config('baidumap.width'),
            'hight' => config('baidumap.height'),
            'staticimage' => config('baidumap.staticimage'),
            'center' => $center,
            'markers' => $center,
            'output' => 'json'
        ];
        $url = config('baidumap.url').config('baidumap.staticimage').http_build_query($data);
        $res = doCurl($url);
        // dump($res);exit; // 接口调试
        return $res;
    }
}
